package com.lighting.lightingservice.service;

import com.aliyun.oss.model.OSSObjectSummary;
import com.lighting.lightingservice.dto.Page;
import com.lighting.lightingservice.dto.Video;
import com.lighting.lightingservice.mapper.PageMapper;
import com.lighting.lightingservice.mapper.VideoMapper;
import com.lighting.lightingservice.utils.AliOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataService {
    @Autowired
    PageMapper pageMapper;


    public Page getPageByDB(){
        List<Page> all = pageMapper.findAll();

        for (Page page : all) {
            System.out.println(page.getSliderImgUrl1() +"\n"+ page.getSliderTitleUp1() +"\n"+ page.getSliderTitleDown1() +"\n"+
                    page.getSliderImgUrl2() +"\n"+ page.getSliderTitleUp2() +"\n"+ page.getSliderTitleDown2() +"\n"+
                    page.getSliderImgUrl3() +"\n"+ page.getSliderTitleUp3() +"\n"+ page.getSliderTitleDown3() +"\n"+
                    page.getMainVideo() +"\n"+ page.getMainVideoImg() +"\n"+
                    page.getMidTitleUp() +"\n"+ page.getMidTitleDown() +"\n"+
                    page.getBlockTitle1() +"\n"+ page.getBlockTitle2() +"\n"+ page.getBlockTitle3() +"\n"+ page.getBlockTitle4() +"\n"+
                    page.getBlockImg1() +"\n"+ page.getBlockImg2() +"\n"+ page.getBlockImg3() +"\n"+ page.getBlockImg4() +"\n"+
                    page.getBlockVideo1() +"\n"+ page.getBlockVideo2() +"\n"+ page.getBlockVideo3() +"\n"+ page.getBlockVideo4());
            return page;
        }
        return null;
    }

    public void setSliderTitleUp1(String sliderTitleUp1){
        pageMapper.updateSliderTitleUp1(sliderTitleUp1);
    }

    public void setSliderTitleDown1(String sliderTitleDown1){
        pageMapper.updateSliderTitleDown1(sliderTitleDown1);
    }

    public void setSliderTitleUp2(String sliderTitleUp2){
        pageMapper.updateSliderTitleUp2(sliderTitleUp2);
    }

    public void setSliderTitleDown2(String sliderTitleDown2){
        pageMapper.updateSliderTitleDown2(sliderTitleDown2);
    }

    public void setSliderTitleUp3(String sliderTitleUp3){
        pageMapper.updateSliderTitleUp3(sliderTitleUp3);
    }

    public void setSliderTitleDown3(String sliderTitleDown3){
        pageMapper.updateSliderTitleDown3(sliderTitleDown3);
    }


    public void setMidTitleUp(String midTitleUp){
        pageMapper.updateMidTitleUp(midTitleUp);
    }

    public void setMidTitleDown(String midTitleDown){
        pageMapper.updateMidTitleDown(midTitleDown);
    }


    public void setBlockTitle1(String blockTitle1){
        pageMapper.updateBlockTitle1(blockTitle1);
    }

    public void setBlockTitle2(String blockTitle2){
        pageMapper.updateBlockTitle2(blockTitle2);
    }

    public void setBlockTitle3(String blockTitle3){
        pageMapper.updateBlockTitle3(blockTitle3);
    }

    public void setBlockTitle4(String blockTitle4){
        pageMapper.updateBlockTitle4(blockTitle4);
    }



    //**********************  视频OSS数据处理  **********************
    public String[] getAllOSS(){
        List<OSSObjectSummary> oss = AliOSSUtils.GetAllOSSData();

        //初始化需要得到的数组
        String[] array = new String[oss.size()];

        //使用for循环得到数组
        for(int i = 0; i < oss.size(); i++){
            array[i] = oss.get(i).getKey();
        }

        return array;
    }
}
